package com.aorise.service.camera.impl;

import com.aorise.mapper.camera.AlarmMapper;
import com.aorise.model.camera.AlarmModel;
import com.aorise.service.camera.AlarmService;
import com.aorise.service.camera.CameraGroupService;
import com.aorise.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author:psl
 * @Desicription:
 * @Date:Created in  2019-05-28.
 * @Modified By:
 */
@Service
public class AlarmServiceImpl implements AlarmService {

    @Autowired
    private AlarmMapper alarmMapper;
    @Autowired
    private CameraGroupService cameraGroupService;


    /**
     * @Author:psl
     * @Description 根据条件查询智能预警信息
     * @params: map 查询条件Map
     * @Date:2019-05-28
     * @Return: List<AlarmModel> 智能预警集合
     * @Modified By:
     */
    @Override
    public List<AlarmModel> getAlarmList(Map<String, Object> map,Page page) throws Exception {
        List<AlarmModel> alarmModels = null;
        Integer count = alarmMapper.getCountAlarm(map);
        if (count > 0) {
            page.setTotalCount(Long.valueOf(count));
            page.setTotalPage(Long.valueOf(count), page.getEveryPage());
            if (page.getCurrentPage() > 0 && page.getEveryPage() > 0) {
                /**查询分页条数*/
                alarmModels = alarmMapper.getAlarmList(map);
                for (int i = 0; i < alarmModels.size(); i++) {
                    if (alarmModels.get(i).getGroupId() != null && alarmModels.get(i).getGroupId() != 0) {
                        String groupName = cameraGroupService.getCameraGroupNameById(alarmModels.get(i).getGroupId());
                        alarmModels.get(i).setGroupName(groupName);
                    }
                }
            }
        } else {
            page.setTotalCount(0L);
        }
        return alarmModels;
    }
}
